package com.xc.utils;


import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Properties;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.xc.stock.utils.Env;


public class PropertiesUtil {
    private static Logger logger = LoggerFactory.getLogger(PropertiesUtil.class);

//    private static Properties props;
//
//    static {
//        String fileName = "stock2guo.properties";
//        props = new Properties();
//        try {
//            props.load(new InputStreamReader(PropertiesUtil.class.getClassLoader().getResourceAsStream(fileName), "UTF-8"));
//        } catch (IOException e) {
//            logger.error("配置文件读取异常", e);
//        }
//    }

    public static String getProperty(String key) {
       return getProperty(key, null);
    }


    public static String getProperty(String key, String defaultValue) {
    	Env env = Env.of();
    	return getProperty(env, key, defaultValue);
    }
    
    public static String getProperty(Env env, String key, String defaultValue) {
    	if(env == null) {
    		logger.warn("找配置信息 key: {} 时环境未初始化完成! ", env);
    		return defaultValue;
    	}
    	
        String value = env.environment().getProperty(key.trim());
        if (StringUtils.isBlank(value)) {
            value = defaultValue;
        }
        return StringUtils.trim(value);
    }
}

